define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
	    this.isInSearch = false;
	    this.loadDone = false;
		this.callParent();
	};

	Model.prototype.mallDataCustomRefresh = function(event){
	    if(event.source.count() < event.offset){
	    	return;
	    }
	    this.comp("popOver1").show();
	    var me = this;
	    var page = event.offset/event.limit + 1;
		var url = this.getParentModel().serverUrl + "/ex_community/a/api/community/getVegetable?callback=?";
		$.getJSON(
				url,
				{
					pageNo:page,
					pageSize:event.limit
				},
				function(data){
					if(data && data.data){
						event.source.loadData(data.data,true,null,event.offset,true);
						me.loadDone = true;
						me.comp("popOver1").hide();
					}
				}
		);

	};
	
	Model.prototype.getImageUrl = function(path){
	    var imageUrl = path?this.getParentModel().serverUrl+path:"$UI/communityOto/home/img/phone.jpg";
		return  imageUrl;
	};
	

	Model.prototype.goodsClick = function(event){
	
		var currentRow = this.comp("mallData").getCurrentRow();
		var option = {
				"title":currentRow.val("name"),
				"description":currentRow.val("description"),
				"images":currentRow.val("images"),
				"introduce":currentRow.val("introduce"),
				"price":currentRow.val("price")
		};
		justep.Shell.showPage("$UI/communityOto/home/goods.w",option);

	};
	

	Model.prototype.backBtnClick = function(event){
	    if(this.isInSearch){
	    	this.isInSearch = false;
	    	this.comp('mallData').refreshData();
	    	this.comp("searchContent").val('');
	    }else{
	    	this.comp("windowReceiver1").windowEnsure();
		    this.getParentModel().goBackHome();
	    }
		

	};
	
	Model.prototype.showSearchButtonClick = function(event){
	
		$('.search-panel').slideToggle();

	};
		
	Model.prototype.searchButtonClick = function(event){
	   
		var searchUrl = this.getParentModel().serverUrl + "/ex_community/a/api/community/getVegetable?callback=?";
		var title = this.comp("searchContent").val();
		var me  = this;
		if(title){
			$.getJSON(searchUrl,{'category.id':this.currentId,'name':title},function(data){
				if(data && data.data){
				    me.isInSearch = true;
					me.comp('mallData').loadData(data.data);		
				}
			});
		}
	};
	

	Model.prototype.scrollView1PullDown = function(event){
		this.comp("mallData").refreshData();

	};
	

	Model.prototype.scrollView1PullUp = function(event){
		if(this.loadDone){
			this.loadDone = false;
			this.comp("mallData").loadNextPageData();
		}
		
	};
	

	Model.prototype.mallDataBeforeRefresh = function(event){
		this.loadDone = false;

	};
	

	return Model;
});